﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;

namespace Convertor.Plugin.Split
{
    [Serializable]
    public class ConfigContent : IConfigContent, ISerializable, ICloneable, INotifyPropertyChanged
    {
        private string splitor = "\r\n";

        public string Splitor
        {
            get { return splitor; }
            set
            {
                splitor = value; if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Splitor"));
                    PropertyChanged(this, new PropertyChangedEventArgs("ToolTip"));
                }
            }
        }

        public ConfigContent()
        {
        }

        public override string ToString()
        {
            return ToolTip;
        }

        #region IToolTip 成员

        public string ToolTip
        {
            get { return string.Format(UILanguage.TryFindResource("Plugin_Split_Info"), Regex.Escape(this.splitor)); }
        }

        #endregion

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region ISerializable 成员

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Splitor", Splitor, typeof(string));
        }

        public ConfigContent(SerializationInfo info, StreamingContext context)
        {
            // Reset the property value using the GetValue method.
            splitor = (string)info.GetValue("Splitor", typeof(string));
        }

        #endregion

        #region ICloneable 成员

        public object Clone()
        {
            ConfigContent a = new ConfigContent()
            {
                Splitor = this.splitor
            };
            return a;
        }

        #endregion

    }
}
